﻿
@{
    Layout = null;
}

<!DOCTYPE html>

<html>
<head>
    <meta charset="utf-8">
    <title>layui</title>
    <meta name="renderer" content="webkit">
    <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
    <meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1">
    <link href="~/layuimini/lib/layui-v2.6.3/css/layui.css" rel="stylesheet" />
    <link href="~/layuimini/css/public.css" rel="stylesheet" />
    <style>
        body {
            background-color: #ffffff;
        }
    </style>
</head>
<body>

    <div id="test4" class="demo-transfer"></div>
    <div>
        <button class="layui-btn layui-btn-normal" id="saveBtn">确认保存</button>
    </div>

    <script src="~/layuimini/lib/layui-v2.6.3/layui.js"></script>

    <script>
		layui.use(['transfer', 'layer', 'util'], function () {
			var $ = layui.$
				, transfer = layui.transfer
				, layer = layui.layer
				, util = layui.util;

			//获取菜单备选数据
			$.ajax({
                url: 'http://localhost:31861/api/RoleInfo/GetBindMenuInfo',
				type: 'get',
				data: {
                    roleInfoid: parent.roleInfoId
				},
				success: function (res) {
					var date = [];
                    for (var i = 0; i < res.datas.menuInfoOptions.length; i++) {
						date.push({
                            "value": res.datas.menuInfoOptions[i].id, "title": res.datas.menuInfoOptions[i].title
						});
					}

					//显示搜索框
					transfer.render({
						elem: '#test4'
                        , data: date
						, title: ['未绑定', '已绑定']
						, showSearch: true
						, id: 'demo1' //定义索引
                        , value: res.datas.menuInfoIds
					})
				}
			})


			//监听提交
			$('#saveBtn').click(function () {
				//判断菜单是否存在
                if (parent.roleInfoId) {
					//获取右侧数据
					var getData = transfer.getData('demo1');

					//获取选择的角色id数组
                    var menuInfoid = [];
					for (var i = 0; i < getData.length; i++) {
                        menuInfoid.push(getData[i].value);
					}

					//异步请求添加数据
					$.ajax({
                        url: 'http://localhost:31861/api/RoleInfo/BinRoleInfo',
						type: 'post',
                        data: { roleInfoid: parent.roleInfoId, menuInfoid: menuInfoid},
						success: function () {
							layer.msg('成功');
						}
					});
				}
				else {
					layer.msg('数据错误');
				}
			});
		});
    </script>

</body>
</html>
